<template>
   <div>
     <el-button @click="handleClose" type="primary" style="position:absolute;left: 10px;top:10px">返回主菜单</el-button>
     <h1>流程节点配置开关</h1>
     <h5 style="color: red;">(关闭开关后审核流程将默认审核通过，请谨慎操作)</h5>
     <el-row>
       <el-col span="6">
         <span>需求内容审核</span>
       </el-col>
       <el-col span="10">
         <el-switch
           style="display: block"
           v-model="creativeRequestDetailAuditEnable"
           active-color="#13ce66"
           inactive-color="#ff4949"
           >
         </el-switch>
       </el-col>
     </el-row>
     <el-row>
       <el-col span="6">
         <span>素材验收</span>
       </el-col>
       <el-col span="10">
         <el-switch
           style="display: block"
           v-model="creativeRequestProdAuditEnable"
           active-color="#13ce66"
           inactive-color="#ff4949"
           >
         </el-switch>
       </el-col>
     </el-row>
     <el-row>
       <el-col span="6">
         <span>素材短ID生成置后</span>
       </el-col>
       <el-col span="10">
         <el-switch
           style="display: block"
           v-model="creativeShortIdPositionEnable"
           active-color="#13ce66"
           inactive-color="#ff4949"
         >
         </el-switch>
       </el-col>
     </el-row>
     <el-row>
       <el-col style="text-align: right;">
         <el-button type="primary" @click="handleSubmit">保 存</el-button>
         <el-button @click="handleClose">取 消</el-button>
       </el-col>
     </el-row>

 </div>
</template>

<script>
import {mapGetters} from "vuex";
import {setVariable} from "@/api/system/tenant";
import {getTenantSwitch} from "../../../api/business/thirdpartyevmp";

export default {
  name: "TenantSwitch",
  props: {
    close: Function,
  },
  data() {
    return {
      creativeRequestDetailAuditEnable: true,
      creativeRequestProdAuditEnable: true,
      creativeShortIdPositionEnable:false
    }
  },
  computed: {
    ...mapGetters(["userInfo"]),
  },
  mounted() {
    this.creativeRequestDetailAuditEnable = (this.userInfo.detail.tenantVariables['ENABLE_REQUEST_DETAIL_AUDIT'] == 'true');
    this.creativeRequestProdAuditEnable = (this.userInfo.detail.tenantVariables['ENABLE_REQUEST_PROD_AUDIT'] != 'false');
    this.creativeShortIdPositionEnable = (this.userInfo.detail.tenantVariables['ENABLE_SHORTID_POSITION'] == 'true');

  },
  methods:{
    handleSubmit() {
      let detail_audit = this.creativeRequestDetailAuditEnable ? 'true':'false';
      let audit_enable = this.creativeRequestProdAuditEnable ? 'true':'false';
      let shortIdEnable = this.creativeShortIdPositionEnable ? 'true':'false';
      let variables = [
        {key: 'ENABLE_REQUEST_DETAIL_AUDIT', value: detail_audit},
        {key: 'ENABLE_REQUEST_PROD_AUDIT', value: audit_enable},
        {key: 'ENABLE_SHORTID_POSITION', value: shortIdEnable},
      ];
      this.userInfo.detail.tenantVariables['ENABLE_REQUEST_DETAIL_AUDIT'] = detail_audit;
      this.userInfo.detail.tenantVariables['ENABLE_REQUEST_PROD_AUDIT'] = audit_enable;
      this.userInfo.detail.tenantVariables['ENABLE_SHORTID_POSITION'] = shortIdEnable;
      setVariable(JSON.stringify(variables)).then((res)=>{
        if(res.data.success) {
          this.$message.success("设置已生效");
          this.handleClose();
        }
      });
    },
    handleClose() {
      if(this.close) {
        this.close();
      } else {
        this.goback();
      }
    },
    goback(){
      this.$router.go("/system/Navigation");//返回上一层
    },
  }
}
</script>

<style scoped>

</style>
